import {arrange} from './base'
class Calculate{
    /**
     * 计算注数
     * 
     * @param {any} active 当前选中 
     * @param {any} play_name  玩法名
     * @memberof Calculate
     */
    computeCount(active, play_name){
        let count = 0
        const exist = this.play_list.has(play_name)
        const arr = new Array(active).fill('0')
        if(exist && play_name.at(0) === 'r'){
            count = Calculate.combine(arr, play_name.split('')[1]).length
        }
        return count
    }

    /**
     * 计算奖金金额 奖金规则是？？？？
     * 
     * @param {any} active 
     * @param {any} play_name 
     * @memberof Calculate
     */
    computeBonus(active, play_name){
        const play = play_name.split('')
        const _this = this
        let arr = new Array(play[1]*1).fill(0)
        let min, max
        if(play[0] === 'r'){
            let min_active = 5-(11-active)
            if(min_active>0){
                if(min_active-play[1]>=0){
                    arr = new Array(min_active).fill(0)
                    min = Calculate.combine(arr, play[1]).length
                }else{
                    if(play[1]-5>0 && active-play[1]>0){
                        arr= new Array(active-5).fill(0)
                        min= Calculate.combine(arr,play[1]-5).length
                    }else{
                        min = active-play[1]>-1?1:0
                    }
                }
            }else{
                min = active-play[1]>-1?1:0
            }
            let max_active = Math.min(active, 5)
            if(play[1]-5>0){
                if(active-play[1]>=0){
                    arr = new Array(active - 5).fill(0)
                    max = Calculate.combine(arr, play[1]-5).length
                }else{
                    max = 0
                }
            }else if(play[1]-5<0){
                arr = new Array(Math.min(active,5)).fill(0)
                max = Calculate.combine(arr, play[1]).length
            }else{
                max = 1
            }
        }
        return [min, max].map(item=>{
           return item * _this.play_list.get(play_name).bonus
        })
    
    }

/**
 * 组合运算 4-4
 * 不需要具体的组合？哪还递归个球啊，直接用公式解决不就好了
 * @static
 * @param {any} arr 
 * @param {any} size 
 * @memberof Calculate
 */
static combine(arr, size){
    let allResult = []
    function f(arr, size, result) {
        let arrLen = arr.length
        if(size> arrLen){
            return;
        }
        if(size === arrLen){
            allResult.push([].concat(result,arr))
        }else{
            for(let i = 0;i<arrLen;i++){
                let newResult = [].concat(result)
                newResult.push(arr[i]);
                if(size ===1){
                    allResult.push(newResult)
                }else{
                    let newArr = [].concat(arr)
                    newArr.splice(0, i+1)
                    f(newArr, size-1, newResult)
                }
            }
        }
    }
    f(arr, size, [])
    return allResult
        // return arr.length > size ? arrange(arr.length, size) : false 
    }

}

export default Calculate